<?php
/**
 * Created by PhpStorm.
 * User: 秋枫雁飞
 * Date: 2019/5/7
 * Time: 15:45
 */

namespace Aiweline\Core\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallSchema implements InstallSchemaInterface
{
    const table_MJD_EMAIL_WAIT_SEND_ENTITY = 'mjd_email_wait_send_entity';
    const fields_ENTITY_ID = 'entity_id';
    const fields_MODULE = 'module';
    const fields_TO_NAME = 'to_name';
    const fields_TO_EMAIL = 'to_email';
    const fields_SEND_MESSAGE = 'send_message';
    const fields_CREATE_TIME = 'create_time';
    const fields_SEND_TIME = 'send_time';
    const fields_STATUS = 'status';

    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();
        # Table customer_entity_extend_erp_data:import customer data log
        $table = $installer->getConnection()->newTable(
            $installer->getTable(self::table_MJD_EMAIL_WAIT_SEND_ENTITY)
        )->addColumn(
            self::fields_ENTITY_ID,
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            array('identity' => true, 'nullable' => false, 'primary' => true),
            '实体id'
        )->addColumn(
            self::fields_MODULE,
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            60,
            array('nullable' => false),
            '模块'
        )->addColumn(
            self::fields_TO_NAME,
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            array('nullable' => false),
            '接受者名称'
        )->addColumn(
            self::fields_TO_EMAIL,
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            128,
            array('nullable' => false),
            '接受者邮箱'
        )->addColumn(
            self::fields_SEND_MESSAGE,
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            1000,
            array('nullable' => true),
            '发送内容'
        )->addColumn(
            self::fields_CREATE_TIME,
            \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
            60,
            array('nullable' => false),
            '创建时间'
        )->addColumn(
            self::fields_SEND_TIME,
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            60,
            array('nullable' => false, 'default' => 0),
            '发送时间'
        )->addColumn(
            self::fields_STATUS,
            \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
            null,
            array('nullable' => false, 'default' => 0),
            '0：等待发送，1:发送成功，2：发送失败'
        )->setComment(
            '异步邮件发送表'
        );
        $installer->getConnection()->createTable($table);
        $installer->endSetup();
    }
}